{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">会员管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <div class="temTable layui-fluid"><div class="temTable-member-list layui-fluid">
                手机号：
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="mobile" name=mobile" >
                </div>
                用户创建时间：
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="addtime" name="addtime" >
                </div>
                状态：
                <div class="layui-inline">
                    <select name="status" id="status">
                        <option value="">请选择申请状态</option>
                        <option value="-1">审核未通过</option>
                        <option value="1">审核通过</option>
                    </select>
                </div>
                <button class="layui-btn search" data-type="reload">搜索</button>
            </div>
            </div>
            <table class="layui-hide" id="table" lay-filter="table"></table>
            <script type="text/html" id="barTool">
                {{#  if(d.status == 1){ }}
                <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>
                {{#  } else if(d.status == 0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="examine">审核</a>
                <a class="layui-btn layui-btn-xs" lay-event="refuse">拒绝</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['table','laydate','form'], function() {
        var table = layui.table,
            $ = layui.$
            ,laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#addtime'
            ,type: 'datetime'
            ,range: true
        });

        table.render({
            elem: '#table',
            toolbar: '#toolbarDemo',
            url: '{:url("admin/volunteer/index")}',
            cols: [
                [
                    { field: 'id', width: 80, title: 'ID',fixed:true},
                    { field: 'name', width: 80, title: '姓名'},
                    { field: 'user_id', width: 80, title: '申请人UID' },
                    { field: 'education', width: 120, title: '文化程度'},
                    { field: 'born_date', title: '出生日期' },
                    { field: 'sex', width: 80, title: '性别' },
                    { field: 'mobile',width: 120, title: '联系方式' },
                    { field: 'value',width: 120, title: '政治面貌' },
                    { field: 'bValue',width: 200, title: '支部' },
                    { field: 'rudang_date', width: 160, title: '入党时间'},
                    { field: 'danwei', width: 160, title: '工作单位' },
                    { field: 'personal', width: 160, title: '个人情况' },
                    { field: 'service', width: 160, title: '服务方向' },
                    { field: 'create_time', width: 160, title: '创建时间' },
                    { field: 'statusName',fixed:'right', width: 160, title: '状态'},
                    { fixed: 'right',width:120, title: '操作', toolbar: '#barTool' }
                ]
            ],
            id: 'testReload',
            page: {}
        });

        //监听行工具事件
        table.on('tool(table)', function(obj) {
            var data = obj.data;
            //console.log(obj);
            if (obj.event === 'examine') {
                layer.confirm('审核通过？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/volunteer/examine")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }else if(obj.event === 'refuse'){

                layer.open({
                    type: 2,
                    title: '拒绝申请',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '80%'],
                    content: '/admin/volunteer/fail?id='+data.id    //直接显示某个页面的内容
                });

            }
        });


        var $ = layui.$, active = {
            reload: function () {
                var mobile = $("#mobile").val();
                var time = $("#addtime").val();
                var status = $("#status").val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
//                        key: {
                        mobile: mobile,
                        time: time,
                        status: status
//                        }
                    }
                });
            }
        };
        $('.temTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
{/block}